class Admin::Api::ProductsController < Admin::Api::BaseController

  def index
    @products = Product.all
    items = @products.map{|c| c.summary_builder}
    api_success(message: '', data: { items: items })
  end

  def create
    @product = Product.create(name: params[:name])
    if @Product.save
      api_success(data: {Product: @product.summary_builder})
    else
      api_error
    end
  end

  def update
    @product = Product.find_by(id: params[:id])
    if @product.update(name: params[:name])
      api_success
    else
      api_error
    end
  end

  def show
    @product = Product.find_by(id: params[:id])
    if @product
      api_success(data: {product: @product.detail_builder})
    else
      api_error
    end
  end

end
